//
//  NameEditView.m
//  markmap
//
//  Created by 甘世清 on 2024/4/26.
//

#import "NameEditView.h"

@implementation NameEditView

- (void)SQ_UIViewForSelfView{
    self.backgroundColor = SQColor(@"#4A4A4A");
    self.layer.cornerRadius = 48;
    self.layer.masksToBounds = YES;
    [self addSubview:self.textField];
    [self.textField mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self);
        make.width.mas_equalTo(SCREEN_WIDETH-60);
        make.top.equalTo(self).offset(50);
        make.height.mas_equalTo(50);
    }];
    UIView * lineView = [[UIView alloc]init];
    lineView.backgroundColor = SQColor(@"#E434ED");
    [self addSubview:lineView];
    [lineView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.height.mas_equalTo(1);
        make.centerX.equalTo(self);
        make.width.mas_equalTo(SCREEN_WIDETH-60);
        make.top.equalTo(self.textField.mas_bottom).offset(1);
    }];
    HeaderView * xiayibu = [[HeaderView alloc]init];
    xiayibu.image = @"按钮背景";
    xiayibu.text = SQNSLocalString(@"提交");
    xiayibu.colorString = @"#FFFFFF";
    [xiayibu.btn addTarget:self action:@selector(SQ_tijiaoButton) forControlEvents:UIControlEventTouchUpInside];
    xiayibu.font = FONT_MEDIUM(18);
    [self addSubview:xiayibu];
    [xiayibu mas_updateConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self);
        make.width.mas_equalTo(SCREEN_WIDETH-60);
        make.height.mas_equalTo(48);
        make.bottom.equalTo(self.mas_bottom).offset(-FootHeight-30);
    }];
}
-(void)SQ_tijiaoButton{
    if (![self.textField.text isNotEmpty]) {
        [YJProgressHUD showMsgWithoutView:@"请输入昵称!"];
        return;
    }
    if (self.textField.text.length > 8||self.textField.text.length<2) {
        [YJProgressHUD showMsgWithoutView:@"昵称长度为2至8个字符"];
        return;
    }
    [YJProgressHUD SQ_showMsgWithoutView:@""];
    NSMutableDictionary * dic = [[NSMutableDictionary alloc]init];
    [dic setObject:self.textField.text forKey:@"name"];
    [HttpTool post:Url5 paramDic:dic successBlock:^(BaseModel * _Nonnull httpModel) {
        [YJProgressHUD showMsgWithoutView:SQNSLocalString(@"昵称已更新,审核后方可生效")];
        if (self.isNameBtnBlock) {
            self.isNameBtnBlock();
        }
    } andFailBloc:^(BaseModel * _Nonnull httpModel, NSError * _Nullable error) {
        [YJProgressHUD showMsgWithoutView:httpModel.message];
    }];
}

- (UITextField *)textField{
    if (!_textField) {
        _textField = [[UITextField alloc]init];
        _textField.backgroundColor = UIColor.clearColor;
        _textField.textColor = UIColor.whiteColor;
        _textField.font = FONT_REGULAR(16);
//        _textField.delegate = self;
        _textField.placeholder = SQNSLocalString(@"请输入你的昵称");
        [_textField setValue:SQColor(@"#999999") forKeyPath:@"placeholderLabel.textColor"];
        _textField.returnKeyType = UIReturnKeyDone;
        _textField.layer.masksToBounds = YES;
        _textField.textAlignment = NSTextAlignmentCenter;
        
    }
    return _textField;
}
@end
